/********************************************************************************************************
 * @file	 tl_log.c
 *
 * @brief    for TLSR chips
 *
 * @author	 chaoxin.zhong@telink-semi.com;
 * @date     Nov. 12, 2019
 *
 * @par      Copyright (c) Telink Semiconductor (Shanghai) Co., Ltd.
 *           All rights reserved.
 *
 *			 The information contained herein is confidential and proprietary property of Telink
 * 		     Semiconductor (Shanghai) Co., Ltd. and is available under the terms
 *			 of Commercial License Agreement between Telink Semiconductor (Shanghai)
 *			 Co., Ltd. and the licensee in separate contract or the terms described here-in.
 *           This heading MUST NOT be removed from this file.
 *
 * 			 Licensees are granted free, non-transferable use of the information in this
 *			 file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************************************/

#include "tl_log.h"


uint32_t LogInsertFlag=0;


uint32_t			log_evt_index = 0x00;
uint32_t			chr_evt_index = 0x00;
//rm_log_event log_event[EVT_CNT_IN_RAM];
// uint16_t			log_event_flash_index[EVT_CNT_IN_RAM];

 uint16_t 			log_event_ram_cnt = 0;
 uint8_t 			log_event[20][5];
 uint16_t 			chr_event_ram_cnt = 0;
 uint8_t 			chr_event[20][16];

 uint16_t			log_flash_cnt = 0;

uint8_t 			log_push_notify_en = 0;

uint8_t 			chr_push_notify_en = 0;

uint32_t			tick_log_notify_start = 0;

uint32_t	Fm24c1024_tick = 0;



//log计时标志
 uint8_t  flash_log_flag=0;
volatile uint32_t flash_log_tiner_tick=0;

/**
 * @brief 0.1mS调一次
 */
void app_flash_log_timer_tick_0_1_ms_callback(void)
{
    flash_log_tiner_tick ++;
    if(flash_log_tiner_tick >= FLASH_LOG_TIMER_N)
    {
        flash_log_tiner_tick = 0x00;
    }
    if(flash_log_tiner_tick == (FLASH_LOG_TIMER_N - 1))
    {
        flash_log_flag = 1;
    }
}

/**
* @brief log 进程
*
*/
void app_flash_log_save(uint32_t offset,uint8_t *pdata,uint16_t length)
{
	uint8_t temp_buf[256];
	memset(temp_buf,0xff,256);
	uint8_t mod_v =(offset)%256;
	uint32_t index= offset/256;
	if(mod_v!=0)
	{
		app_iwt_clr();
		app_spi_flash_page_read(0+(index*256),temp_buf,LIST_QUEUE_MAX_BUF_NUM);
	}
	memcpy(&temp_buf[mod_v],pdata,length);
	app_iwt_clr();
	app_spi_flash_page_write(0 + (index*256),temp_buf,LIST_QUEUE_MAX_BUF_NUM);
	app_iwt_clr();

	if(mod_v+length>256)
	{
		memcpy(&temp_buf[mod_v],pdata,256-mod_v);
		app_spi_flash_page_write(0 + (index*256),temp_buf,LIST_QUEUE_MAX_BUF_NUM);
		app_iwt_clr();
		memset(temp_buf,0xff,256);
		memcpy(temp_buf,&pdata[256-mod_v],length-(256-mod_v));
		app_spi_flash_page_write(0 + ((index+1)*256),temp_buf,LIST_QUEUE_MAX_BUF_NUM);
		app_iwt_clr();

		}else{
		memcpy(&temp_buf[mod_v],pdata,length);
		app_iwt_clr();
		app_spi_flash_page_write(0 + (index*256),temp_buf,LIST_QUEUE_MAX_BUF_NUM);
		app_iwt_clr();
	}
}

uint32_t log_byte_length = 0;


#define PAGE_SIZE 256

int fm_24c1024_write_data(unsigned char* data,int data_len, unsigned int start_address)
{
	uint8_t ret=0;
	uint32_t mod_v=start_address%PAGE_SIZE;

	if((mod_v+data_len)>PAGE_SIZE)
	{

		app_flash_log_save(start_address,data,PAGE_SIZE-mod_v);

		int count=data_len-PAGE_SIZE+mod_v;
	
		int index= PAGE_SIZE-mod_v;
		
		while (count > 0)
		{
			int temp_len = (count >= PAGE_SIZE) ? PAGE_SIZE : count;				//page write: 8-byte
			count -= temp_len;
//			ret = iic_register_write(FM24C1024_IIC_WRITE_ADDRESS,start_address+ index, 2, data+ index, data_len);
			if(!((start_address+ index)%0x1000)){
//				while(!ret)
				{
					app_spi_flash_sector_or_block_erase(start_address+ index,FLASH_SECTOR_SIZE);
					
				}
			}
			app_flash_log_save(start_address+ index, data+index, temp_len);
//			if(ret)printf("iic_register_write 2 ok\n");
//			else printf("iic_register_write 2 fail\n");
			index += temp_len;
		}
	}
	else
	{
//		if(mod_v==0)
//		{
//			app_spi_flash_sector_or_block_erase(start_address);
//		}
		if(!(start_address%0x1000)){
//			while(!ret)
			{
				
				app_spi_flash_sector_or_block_erase(start_address,FLASH_SECTOR_SIZE);
					
			}
		}

		app_flash_log_save(start_address,data,data_len);

	}

	return 0;// success end
}

void set_log_notify_en(uint8_t en)
{
	log_push_notify_en = en;
	return;
}
void set_chr_notify_en(uint8_t en)
{
	chr_push_notify_en = en;
	return;
}

uint8_t get_log_notify_en()
{
	return log_push_notify_en;
}

//eeprom_log_byte_length_addr

uint8_t set_log_evt_index(uint32_t index)
{
	uint8_t ret=0;

//	if(index == 0)
//	{
//		app_spi_flash_sector_or_block_erase(LOG_ADDR);
//	}
	index &= 0x00ffffff;
	#if MaintenanceLogMode
		index |= MAINTENANCE_LOG_DATA_CHECK;
	#elif  CHRLogMode
		index |= CHR_LOG_DATA_CHECK;
	#endif
//	ret = fm_24c1024_write_data(&index,4,eeprom_log_evt_index_addr);
//	while(!ret)
	{
	
			app_spi_flash_sector_or_block_erase(LOG_INDEX_ADDR,FLASH_SECTOR_SIZE);
			app_flash_log_save(LOG_INDEX_ADDR,(uint8_t*)&index,4);
	
	}
//	if(!ret)
//	{
		return LOG_SUCCESS;
//	}
//	else
//	{
//		return LOG_FAIL;
//	}

}
uint32_t get_log_evt_index(void)
{
	uint8_t ret;
	uint32_t index = 0;

//	FM24C1024_Init();
//	ret = iic_register_read(FM24C1024_IIC_READ_ADDRESS,eeprom_log_evt_index_addr,0x02,&index, 4);
	app_spi_flash_page_read(LOG_INDEX_ADDR, (uint8_t*)&index, 4);
//	iic_gpio_fun(I2C_GPIO_SDA_E2,I2C_GPIO_SCL_E0);
//	if(ret)
	{
//		printf("get_log_evt_index ok\n");


		#if MaintenanceLogMode
			if((index & 0xff000000) != MAINTENANCE_LOG_DATA_CHECK)
			{
				printf("get_MAINTENANCE_log_evt_index ok init\n");
				set_log_evt_index(0);
				index=0;
			}

		#endif
		index &= 0x00ffffff;

		return index;
	}
//	else
//	{
//		printf("get_log_evt_index fail\n");
//		return LOG_FAIL;
//	}
}

uint8_t set_chr_evt_index(uint32_t index)
{
#if 0
	uint8_t ret=0;


	index &= 0x00ffffff;

	#if  CHRLogMode
		index |= CHR_LOG_DATA_CHECK;
	#endif
//	ret = fm_24c1024_write_data(&index,4,eeprom_log_evt_index_addr);
//	while(!ret)
	{
		if(bls_ll_requestConnBrxEventDisable()>300)
		{
			bls_ll_disableConnBrxEvent();
			app_spi_flash_sector_or_block_erase(CFG_DEVICE_MODE_ADDR);
			app_flash_log_save(CFG_DEVICE_MODE_ADDR,4,(uint8_t*)&index);
			ret=1;
			bls_ll_restoreConnBrxEvent();
		}
	}
//	printf("chr_evt_index %d\n",chr_evt_index);
//	if(!ret)
//	{
		return LOG_SUCCESS;
//	}
//	else
//	{
//		return LOG_FAIL;
//	}
#endif
}



void log_init(void)
{
	LogInsertFlag=0;
	log_evt_index = get_log_evt_index();
	//log_byte_length = get_log_byte_length();

}
int log_ctrl_callback(uint8_t *dat)
{


	return  0;
}

int chr_ctrl_callback(uint16_t connHandle,uint8_t *dat)
{

	return 0;
}

uint8_t log_flash_add(uint8_t *p)
{
	uint8_t ptmp[12];

	if(log_evt_index<=EVT_CNT_IN_FLASH_MAX)	// should not exceed.
	{			
		//my_printf_aaa("log_evt_index=%x\r\n", log_evt_index);
			
		fm_24c1024_write_data(p,sizeof(rm_log_event),12*log_evt_index);	//FLASH_EVT_ADDR
		/*WaitMs(5);
		i2c_read_series((log_evt_index*12), 2, ptmp, 12);
		WaitMs(5);
		if((ptmp[0] == 0x00)&&(ptmp[1]==0x00)){
			while(1);
		}
		my_printf_aaa("ptmp=%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\r\n", ptmp[0],ptmp[1],ptmp[2],ptmp[3],ptmp[4],ptmp[5],ptmp[6],ptmp[7],ptmp[8],ptmp[9],ptmp[10],ptmp[11]);
		*/
		//log_flash_cnt++;

		return 1;
	}else{
		log_evt_index = 1;
	}
	
	return 0;
}



uint32_t log_evt_index_map=0;
uint8_t log_evt_index_map_flag=0;




void rec_single_evt_test(uint8_t serid,uint8_t cmdid,uint8_t type,uint8_t len,uint8_t val)
{
#if MaintenanceLogMode
	uint8_t i;
	uint8_t ret;

	uint8_t p[5];
	p[0] = serid;
	p[1] = cmdid;
	p[2] = type;
	p[3] = len;
	p[4] = val;

//	if(ble_status_aaa==BEGIN_CONNECTED_STATUS_AAA||ble_status_aaa==OK_CONNECTED_STATUS_AAA)
	{
		if(log_event_ram_cnt<19)
		{
			log_event[log_event_ram_cnt][0]=p[0];
			log_event[log_event_ram_cnt][1]=p[1];
			log_event[log_event_ram_cnt][2]=p[2];
			log_event[log_event_ram_cnt][3]=p[3];
			log_event[log_event_ram_cnt][4]=p[4];
			log_event_ram_cnt++;

		}else{
			log_event_ram_cnt=0;
		}
		return ;
	}
	if((log_evt_index*MAINTENANCE_LOG_LENGTH) > Max_EEPROM_VOLUME)
	{
		app_spi_flash_sector_or_block_erase(LOG_ADDR,FLASH_SECTOR_SIZE);
		log_evt_index = 0;
		set_log_evt_index(log_evt_index);
	}

//	ret = fm_24c1024_write_data(p,MAINTENANCE_LOG_LENGTH,eeprom_log_evt_baseaddr + log_evt_index*MAINTENANCE_LOG_LENGTH);
//	app_flash_log_save(LOG_ADDR + log_evt_index*MAINTENANCE_LOG_LENGTH,MAINTENANCE_LOG_LENGTH,p);

//	if(!ret)
	{
//		printf("set_log_evt");
//		for(i=0;i<MAINTENANCE_LOG_LENGTH;i++)printf("0x%02X ",p[i]);
//		printf("\n");
//		log_evt_index++;
//		set_log_evt_index(log_evt_index);
//		return LOG_SUCCESS;
	}
//	else
//	{
//		return LOG_FAIL;
//	}
#endif
}

uint16_t ptmp_index = 0;

void task_log_notify_test(void)
{
#if MaintenanceLogMode

	uint8_t i;
	uint8_t ret;
	uint8_t ptemp[12];
	uint8_t ptmp[16];
	
	uint32_t index = 0;
	static uint32_t logaddress=0;

	if( 1 )
	{
		if( log_push_notify_en)
		{
			//if( tick_log_notify_start )
			{
				if(log_evt_index)
				{
//					FM24C1024_Init();
//					ret = iic_register_read(FM24C1024_IIC_READ_ADDRESS,eeprom_log_evt_baseaddr + logaddress*MAINTENANCE_LOG_LENGTH,0x02,ptemp, MAINTENANCE_LOG_LENGTH);
					app_spi_flash_page_read(eeprom_log_evt_baseaddr+logaddress*MAINTENANCE_LOG_LENGTH,ptemp, MAINTENANCE_LOG_LENGTH);
//					iic_gpio_fun(I2C_GPIO_SDA_E2,I2C_GPIO_SCL_E0);
//					if(ret)
					{
						//printf("get_log_evt ");
						ptmp[0] = 0x0a;
						ptmp[1] = 0x05;
						ptmp[2] = ptmp_index;
						memcpy(&ptmp[3],ptemp,MAINTENANCE_LOG_LENGTH);
						
						if( one_wire_bus_app_send_short_keyboard_custom_data(0x80, (uint8_t *)ptmp, MAINTENANCE_LOG_LENGTH+3) == true )
						{
							//for(i=0;i<MAINTENANCE_LOG_LENGTH;i++)printf("0x%02X ",ptemp[i]);
							//printf("\n");
							//my_printf_aaa("ptmp_index=%2X\r\n", ptmp_index);
							//my_printf_aaa("log_evt_index=%2X\r\n", log_evt_index);
							logaddress++;
							log_evt_index--;
							ptmp_index++;
//							set_log_evt_index(log_evt_index);
						}
					}
//					else
//					{
//						printf("get_log_evt_index fail\n");
//						return LOG_FAIL;
//					}
				}
				else
				{
					set_log_evt_index(log_evt_index);
					printf("set_log_notify_en off\n");
					ptmp_index  = 0;
					logaddress=0;
					set_log_notify_en(0);
				}
 
			}
		}
		else
		{

		}
	}
	if(flash_log_flag)
	{
		if(log_event_ram_cnt){

			if(((log_evt_index+log_event_ram_cnt)*MAINTENANCE_LOG_LENGTH) > Max_EEPROM_VOLUME)
			{

				app_spi_flash_sector_or_block_erase(LOG_ADDR,FLASH_SECTOR_SIZE);
				log_evt_index = 0;
				set_log_evt_index(log_evt_index);
			}
			ret = fm_24c1024_write_data(&log_event[0][0],log_event_ram_cnt*MAINTENANCE_LOG_LENGTH,eeprom_log_evt_baseaddr + log_evt_index*MAINTENANCE_LOG_LENGTH);
		//	app_flash_log_save(LOG_ADDR + log_evt_index*MAINTENANCE_LOG_LENGTH,MAINTENANCE_LOG_LENGTH,p);

			if(!ret)
			{
		//		printf("set_log_evt");
				log_evt_index+=log_event_ram_cnt;				
				log_event_ram_cnt=0;
				set_log_evt_index(log_evt_index);
				
			}
			return ;
		}
	}
#endif
}


void rec_single_evt_CHR(uint8_t cmdid,uint8_t info1,uint8_t info2,uint8_t info3,uint8_t info4)
{
#if CHRLogMode

	uint32_t timestamp = 0x12345678;

	uint8_t i;
	uint8_t ret;
	uint8_t p[16];



	timestamp = clock_time();

	p[0] = 0x2D;
	p[1] = 0x02;
	p[2] = 0x01;
	p[3] = 0x0C;


	p[4] = 0x00;
	p[5] = 0x00;

	p[6] = timestamp >> 24;
	p[7] = timestamp >> 16;
	p[8] = timestamp >> 8;
	p[9] = timestamp >> 0;

//	p[10] = 0x11;//DeviceType
	p[10] = 0x07;//DeviceType
	p[11] = cmdid;//EvnetModule

	p[12] = info1;
	p[13] = info2;
	p[14] = info3;
	p[15] = info4;

//	if(ble_status_aaa==BEGIN_CONNECTED_STATUS_AAA||ble_status_aaa==OK_CONNECTED_STATUS_AAA)
	{
		if(chr_event_ram_cnt<19)
		{
			chr_event[chr_event_ram_cnt][0]=p[0];
			chr_event[chr_event_ram_cnt][1]=p[1];
			chr_event[chr_event_ram_cnt][2]=p[2];
			chr_event[chr_event_ram_cnt][3]=p[3];
			chr_event[chr_event_ram_cnt][4]=p[4];
			chr_event[chr_event_ram_cnt][5]=p[5];
			chr_event[chr_event_ram_cnt][6]=p[6];
			chr_event[chr_event_ram_cnt][7]=p[7];
			chr_event[chr_event_ram_cnt][8]=p[8];
			chr_event[chr_event_ram_cnt][9]=p[9];
			chr_event[chr_event_ram_cnt][10]=p[10];
			chr_event[chr_event_ram_cnt][11]=p[11];
			chr_event[chr_event_ram_cnt][12]=p[12];
			chr_event[chr_event_ram_cnt][13]=p[13];
			chr_event[chr_event_ram_cnt][14]=p[14];
			chr_event[chr_event_ram_cnt][15]=p[15];
			chr_event_ram_cnt++;

		}else{
			chr_event_ram_cnt=0;
		}
		return ;
	}

	if((chr_evt_index*CHR_LOG_LENGTH) >= Max_FLASH_VOLUME)
	{
		app_spi_flash_sector_or_block_erase(CFG_MAST_ADDR);
		chr_evt_index = 0;
		set_chr_evt_index(chr_evt_index);
	}

	ret = fm_24c1024_write_data(p,CHR_LOG_LENGTH,CFG_MAST_ADDR + chr_evt_index*CHR_LOG_LENGTH);
	if(!ret)
	{
//		printf("set_log_evt");
//		for(i=0;i<CHR_LOG_LENGTH;i++)printf("0x%02X ",p[i]);
//		printf("\n");
		chr_evt_index++;
		set_chr_evt_index(chr_evt_index);
		return LOG_SUCCESS;
	}
	else
	{
		return LOG_FAIL;
	}
#endif
}
void task_log_notify_CHR(void)
{
#if CHRLogMode

	uint8_t i;
	uint8_t ret;
	uint8_t ptemp[16];
	uint8_t ptmp[16];
	uint32_t index = 0;
	static uint32_t logaddress=0;

	if( blc_ll_getCurrentState() == BLS_LINK_STATE_CONN )
	{
		if( chr_push_notify_en)
		{
//			reset_idle_status();
//			if( tick_log_notify_start && clock_time_exceed(tick_log_notify_start, 1000))
			{
//				tick_log_notify_start = clock_time()|1;
				if(chr_evt_index)
				{
					app_spi_flash_page_read(CFG_MAST_ADDR+logaddress*CHR_LOG_LENGTH, CHR_LOG_LENGTH,ptemp);
//					if(ret)
					{
						ptmp[0] = 0x2D;
						ptmp[1] = 0x02;
						ptmp[2] = 0x01;
						ptmp[3] = 0x0C;

						ptmp[4] = 0x00;
						ptmp[5] = 0x00;
						memcpy(&ptmp[6],ptemp,CHR_LOG_LENGTH);
						//printf("get_log_evt ");
						if( one_wire_bus_app_send_short_keyboard_custom_data(0x90, (uint8_t *)ptmp, CHR_LOG_LENGTH+6) == BLE_SUCCESS )
						{
							//for(i=0;i<CHR_LOG_LENGTH;i++)printf("0x%02X ",ptemp[i]);
							//printf("\n");
							logaddress++;
							chr_evt_index--;
//							set_chr_evt_index(chr_evt_index);
							return LOG_SUCCESS;
						}
					}
//					else
//					{
//						printf("get_log_evt_index fail\n");
//						return LOG_FAIL;
//					}
				}
				else
				{
					set_chr_evt_index(chr_evt_index);
					logaddress=0;
					set_chr_notify_en(0);
				}
			}
			return ;
		}
		else
		{

		}
	}

	if(ble_status_aaa!=BEGIN_CONNECTED_STATUS_AAA||ble_status_aaa!=OK_CONNECTED_STATUS_AAA)
	{
		static uint32_t chraddress=0;
		if(log_event_ram_cnt){

			if(((log_evt_index+log_event_ram_cnt)*MAINTENANCE_LOG_LENGTH) > Max_EEPROM_VOLUME)
			{

					if(bls_ll_requestConnBrxEventDisable()>300){
						bls_ll_disableConnBrxEvent();
						app_spi_flash_sector_or_block_erase(LOG_ADDR,FLASH_SECTOR_SIZE);
						ret=1;
						bls_ll_restoreConnBrxEvent();
					}else{
						return;
					}

				log_evt_index = 0;
				set_log_evt_index(log_evt_index);
			}
//			u_array_printf(&log_event[0][0],log_event_ram_cnt*MAINTENANCE_LOG_LENGTH);
			ret = fm_24c1024_write_data(&log_event[chraddress][0],MAINTENANCE_LOG_LENGTH,eeprom_log_evt_baseaddr + log_evt_index*MAINTENANCE_LOG_LENGTH);
		//	app_flash_log_save(LOG_ADDR + log_evt_index*MAINTENANCE_LOG_LENGTH,MAINTENANCE_LOG_LENGTH,p);

			if(!ret)
			{
		//		printf("set_log_evt");
		//		for(i=0;i<MAINTENANCE_LOG_LENGTH;i++)printf("0x%02X ",p[i]);
		//		printf("\n");
				log_evt_index++;
				chraddress++;
//				log_event_ram_cnt--;
//				set_log_evt_index(log_evt_index);
			}
			if(chraddress==log_event_ram_cnt)
			{
				chraddress=0;
				log_event_ram_cnt=0;
				if(ble_status_aaa<=3){
					set_log_evt_index(log_evt_index);
				}
			}
			return ;
		}

		if(chr_event_ram_cnt)
		{

			if(((chr_evt_index+chr_event_ram_cnt)*CHR_LOG_LENGTH) >= Max_FLASH_VOLUME)
			{
				uint8_t ret = 0;

					if(bls_ll_requestConnBrxEventDisable()>300){
						bls_ll_disableConnBrxEvent();
						app_spi_flash_sector_or_block_erase(CFG_MAST_ADDR);
						ret=1;
						bls_ll_restoreConnBrxEvent();
					}else {
						return;
					}

				chr_evt_index = 0;
				set_chr_evt_index(chr_evt_index);
			}
			ret = fm_24c1024_write_data(&chr_event[chraddress][6],CHR_LOG_LENGTH,CFG_MAST_ADDR + chr_evt_index*CHR_LOG_LENGTH);
			if(!ret){
				chr_evt_index++;
				chraddress++;
//				printf("chr_evt_index %d\n",chr_evt_index);
			}
//			set_chr_evt_index(chr_evt_index);
			if(chraddress==chr_event_ram_cnt)
			{
				chraddress=0;
				chr_event_ram_cnt=0;
				if(ble_status_aaa<=3){
					set_chr_evt_index(chr_evt_index);
				}
			}
		}
	}
#endif
}


void log_pro( void * p )
{
	uint8_t ptmp[30];
	SourcePacketStr *pAttDat = (SourcePacketStr*)p;
	uint16_t log_cmd_adr =  pAttDat->cid | (pAttDat->sid<<8);
	if(log_cmd_adr==0x0A01)
	{
		//set_log_notify_en(1);
		//tick_log_notify_start = clock_time()|1;
		ptmp[0] = 0x0a;
		ptmp[1] = 0x01;
		ptmp[2] = 0x01;
		ptmp[3] = 0x0c;
		ptmp[4] = 'k';
		ptmp[5] = 'e';
		ptmp[6] = 'y';
		ptmp[7] = 'b';
		ptmp[8] = 'o';
		ptmp[9] = 'a';
		ptmp[10] = 'r';
		ptmp[11] = 'd';
		ptmp[12] = '.';
		ptmp[13] = 'l';
		ptmp[14] = 'o';
		ptmp[15] = 'g';
		
		uint8_t status = one_wire_bus_app_send_short_keyboard_custom_data (0x90, (uint8_t *)ptmp, 16);
	}
	else if(log_cmd_adr==0x0A02)
	{
		ptmp[0] = 0x0a;
		ptmp[1] = 0x02;
		ptmp[2] = 0x01;
		ptmp[3] = 0x05;
		ptmp[4] = '1';
		ptmp[5] = '.';
		ptmp[6] = '0';
		ptmp[7] = '.';
		ptmp[8] = '1';
		
		ptmp[9] = 0x02;
		ptmp[10] = 0x01;
		ptmp[11] = 0x00;
		ptmp[12] = 0x03;
		ptmp[13] = 0x02;
		ptmp[14] = 0x00;
		ptmp[15] = 0xDC;
		
		ptmp[16] = 0x04;
		ptmp[17] = 0x02;
		ptmp[18] = 0x08;
		ptmp[19] = 0x98;
		
		ptmp[20] = 0x05;
		ptmp[21] = 0x02;
		ptmp[22] = 0x3a;
		ptmp[23] = 0x98;
		uint8_t status = one_wire_bus_app_send_short_keyboard_custom_data (0x90, (uint8_t *)ptmp, 24);
	}
	else if( log_cmd_adr==0x0A03)
	{
		ptmp[0] = 0x0a;
		ptmp[1] = 0x03;
		
		ptmp[2] = 0x02;
		ptmp[3] = 0x04;
		ptmp[4] = 0x00;
		ptmp[5] = 0x00;
		ptmp[6] = 0x08;
		ptmp[7] = 0xA1;
		
		ptmp[8] = 0x03;
		ptmp[9] = 0x04;
		ptmp[10] = 0x00;
		ptmp[11] = 0x00;
		ptmp[12] = 0x00;
		ptmp[13] = 0x00;
		uint8_t status = one_wire_bus_app_send_short_keyboard_custom_data (0x90, (uint8_t *)ptmp, 14);
	}
	else if( log_cmd_adr==0x0A04)
	{
		ptmp[0] = 0x0a;
		ptmp[1] = 0x04;
		
		ptmp[2] = 0x7f;
		ptmp[3] = 0x04;
		ptmp[4] = 0x00;
		ptmp[5] = 0x01;
		ptmp[6] = 0x86;
		ptmp[7] = 0xA0;
		
		uint8_t status = one_wire_bus_app_send_short_keyboard_custom_data (0x80, (uint8_t *)ptmp, 8);

		set_log_notify_en(1);
	}
}